home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
10,000 Great Games
/
10,000 Great Games.iso
/
Product
/
66
/
data1.cab
/
Source_Files
/
Src
/
Bubble.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-16
|
2KB
|
127 lines
#include "stdafx.h"
cBubble *bubbles = 0;
static cTimer bubble_wait;
void cBubble::make()
{
if (!bubble_wait && !bubble_list.is_empty())
{
new cBubble ();
bubble_wait = 20 * sec + rnd(60 * sec);
}
}
cBubble::cBubble(int _vy, cCharacter *_contents)
: cGameObject(bubble_list.get_random())
{
add((cList **)&bubbles);
set_sequence("MOVING", TRUE);
set_position(rnd(surface->h), surface->start);
make_dirty();
// Set vertical speed
if (_vy <= 0)
vy = BUBBLE_VSPEEDC + rnd(BUBBLE_VSPEEDR);
else
vy = _vy;
// Put contents in there
contents = 0;
capture(_contents);
// invulnerable bubble for outside fire?
invulnerable = contents != 0;
// Set other
armor = 100;
// Call control function directly
control();
}
cBubble::~cBubble()
{
new cEffect (x, y, orig, "EXPLODE");
if (contents != 0)
contents->release();
}
void cBubble::capture(cCharacter *ch)
{
// Capture character?
if (contents == 0 && ch != 0 && !ch->is_captured() && !ch->is_dead())
{
contents = ch;
contents->make_dirty();
contents->capture(this);
contents->set_position(x, y);
contents->make_dirty();
}
}
int cBubble::control()
{
// Check explode
if (armor <= 0)
return FALSE;
// Do movement
cGameObject::control();
// Check if bubble is getting out of screen
if (y < surface->start)
set_position(x, surface->start);
// Adjust horizontal speed
if (!x_on_screen())
vx = -vx / 2;
if (!constant_speed)
{
new_x_push(1, 0, pmrnd(BUBBLE_HSPEEDR));
constant_speed = sec + rnd(BUBBLE_CHANGE);
}
// If empty check if anyone jumps in
if (contents == 0)
capture((cCharacter *)check_radial_boundaries(&cCircle(0, 0, 5), players));
// Move capture around
if (contents != 0)
{
contents->make_dirty();
contents->set_position(x, y - CHAR_HEIGHT / 2);
contents->make_dirty();
}
// Check if on top of screen
return y <= surface->start + surface->h - BUBBLE_EXPLODE_ZONE;
}
void cBubble::hit(cWeapon *w)
{
if (!invulnerable)
armor -= w->armor_power;
}